<template>
  <div class="from">
    <div class="title">
      {{$t('ContainerState_Containerstatus')}}
<!--      容器状态-->
    </div>
    <div v-if="item">
      <div class="item"><span class="span">ID</span>{{ item.Id }}</div>
      <div class="item">
        <span class="span">{{$t('ContainerState_ContainerName')}}</span>
        <span v-show="!editShow">
          {{item.Name}} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <i @click="editNameShow" class="el-icon-edit" :title="$t('ContainerState_Changethename')" style="color: #067FB5; cursor: pointer;"></i>
        </span>
        <span v-show="editShow">
          <el-input size="mini" v-model="name" placeholder="$t('ContainerState_Pleaseinputthecontent')" style="width: 200px;margin-right:10px"></el-input>
          <el-button size="mini" style="background: #067FB5; color: #fff;" @click="editNameShow">{{$t('ContainerInfo_cancel')}}</el-button>
          <el-button size="mini" type="success" @click="editName">{{$t('ContainerInfo_Submit')}}</el-button>
        </span>
      </div>
      <div class="item"><span class="span">{{$t('ContainerState_IPaddress')}}</span>{{ item.NetworkSettings.IPAddress }}</div>
      <div class="item"><span class="span">{{$t('ContainerState_state')}}</span>{{ item.State.Status }}</div>
      <div class="item"><span class="span">{{$t('ContainerState_Creationtime')}}</span>{{ item.Created }}</div>
      <div class="item"><span class="span">{{$t('ContainerState_Starttime')}}</span>{{ item.State.StartedAt }}</div>
    </div>
    <div class="btn" v-if="item">
      <router-link tag="button" :to="'/Container/Logs/' + item.Id">
        <i class="iconfont icon-wulianwang-"></i>
        <span>日志</span>
      </router-link>
      <router-link tag="button" :to="'/Container/CheckContainer/' + item.Id">
        <i class="iconfont icon-gengduo"></i>
        <span>检查</span>
      </router-link>
      <router-link tag="button" :to="'/Container/CountContainer/' + item.Id">
        <i class="iconfont icon-zhenduan"></i>
        <span>统计</span>
      </router-link>
      <router-link tag="button" :to="'/Container/ConsoleContainer/' + item.Id">
        <i class="iconfont icon-minglinghang"></i>
        <span>控制台</span>
      </router-link>
    </div>
  </div>
</template>

<script>
import post from '@/utils/post'
export default {
  data () {
    return {
      editShow: false,
      name: ''
    }
  },
  props: ['item'],
  watch: {
    item: function () {
      this.name = this.item.Name
    }
  },
  methods: {
    // 控制修改框显示与隐藏
    editNameShow () {
      this.editShow = !this.editShow
    },
    // 提交修改
    editName () {
      const docker = `curl -w %{http_code} --unix-socket /var/run/docker.sock -s -X POST "http:/v1.40/containers/${this.item.Id}/rename?name=${this.name}"` // 修改名字
      post({ docker }, res => {
        if (res.message) {
          return this.$message({
            showClose: true,
            message: res.message,
            type: 'error'
          })
        }
        if (res >= 200 && res < 300) {
          this.$message({
            showClose: true,
            message: '修改成功',
            type: 'success'
          })
          this.$emit('success')
          this.editNameShow()
        } else {
          this.$message({
            showClose: true,
            message: '网络不畅，请稍候重试',
            type: 'error'
          })
        }
      }, this)
    }
  }
}
</script>

<style lang="scss" scoped>
.btn{
  margin-top: 20px;
  margin-left: 30px;
  button{
    background: #ebebeb;
    height: 38px;
    line-height: 38px;
    padding: 0px 15px;
    color: #067FB5;
    .iconfont{
      font-size: 16px;
    }
  }
  button:first-of-type{
    border-radius: 5px 0px 0px 5px;
  }
  button:last-of-type{
    border-radius: 0px 5px 5px 0px;
  }
  button:hover{
    background: #067FB5;
    color: #fff;
  }
}
.item{
  padding: 2px;
  height: 40px;
  line-height: 40px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  .span{
    font-size: 16px;
    color: #067FB5;
    width: 120px;
    display: inline-block;
    border-radius: 5px;
    border: #067FB5 1px solid;
    // font-weight: bold;
    text-align: center;
    margin-right: 30px;
    background: #fff;
  }
}
.item:nth-child(2n-1){
  background: #fff;
  span{
    background: #F7FCFF;
  }
}
.from{
  border: 1px solid #067FB5;
  border-radius: 15px;
  padding: 20px 10px 20px 10px;
  margin: 30px 0px;
  background: #F7FCFF;
  position: relative;
  .title{
    position: absolute;
    top: -14px;
    z-index: 10;
    left: 30px;
    font-size: 18px;
    font-weight: bold;
    background: #F7FCFF;
    padding: 0px 5px;
    border-radius: 5px;
  }
}
</style>
